package cn.com.majiang.config.controller;

import cn.com.majiang.config.util.AES;
import cn.com.majiang.config.util.PropertyPlaceholder;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by jiangyanxin on 2017/5/4.
 */

@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
public class ClientConfigController {
    Logger logger = LoggerFactory.getLogger(ClientConfigController.class);

    @RequestMapping(value = "/getclientconfig",method={RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object getclientConfig(HttpServletRequest request)throws Exception{
        String clientid = request.getParameter("clientid");
        String version = request.getParameter("version");
        if(StringUtils.isBlank(clientid)){
            clientid = "0";
        }
        if(StringUtils.isBlank(version)){
            version="1.0.1";
        }
        String clientConfig = PropertyPlaceholder.getProperty(clientid+"_"+version);
        logger.info("配置信息：{}",clientConfig);
        String str = AES.aesEncrypt(clientConfig,"jedt$i&12*&$ncfb");
        logger.info( "加密内容"+str);
        String str1 = AES.aesDecrypt(str,"jedt$i&12*&$ncfb");
        logger.info("解秘内容"+str1);
        return str;
    }

}
